/*
 * Copyright (c) 2021, Texas Instruments Incorporated
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:C:\Users\24884\workspace_ccstheia\empty_LP_MSPM0G3507_nortos_ticlang\Periph\OLED_Hardware_I2C
 *
 * *  Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * *  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * *  Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
//陀螺仪参数wit_data.pitch/wit_data.roll/wit_data.yaw十三个主要参数
//当前PA10，PA11不可用（串口通信接口）
//测速接口：PB19,PA22(跳线配置)，PA24，PA17
#include "ti_msp_dl_config.h"
#include "main.h"
#include "stdio.h"
#include "ENCODER.h"

uint8_t oled_buffer[32];
uint8_t Delay_ms = 0;
bool iu = true;

int main(void)
{
    SYSCFG_DL_init();
    SysTick_Init();
    NVIC_EnableIRQ(TIMER_delay_INST_INT_IRQN);
    Encoder_Init();
    // MPU6050_Init();
    OLED_Init();
    // Ultrasonic_Init();
    // BNO08X_Init();
    WIT_Init();
    DL_TimerG_startCounter(TIMA0);

    Motor_Init();

    OLED_ShowString(0,0,(uint8_t *)"P",8);//俯仰
    OLED_ShowString(0,2,(uint8_t *)"R",8);//滚转
    OLED_ShowString(0,4,(uint8_t *)"Y",8);//偏航

    OLED_ShowString(6*8,2,(uint8_t *)"LE",8);
    OLED_ShowString(6*8,4,(uint8_t *)"LR",8);
    while(iu);//延迟阻塞
    Motor_left(60);
    Motor_right(60);

    while (1) 
    {
        sprintf((char *)oled_buffer, "%-6.1f", wit_data.pitch);
        OLED_ShowString(8,0,oled_buffer,8);
        sprintf((char *)oled_buffer, "%-6.1f", wit_data.roll);
        OLED_ShowString(8,2,oled_buffer,8);
        sprintf((char *)oled_buffer, "%-6.1f", wit_data.yaw);
        OLED_ShowString(8,4,oled_buffer,8);
        sprintf((char *)oled_buffer, "%-d", count_speedL);
        OLED_ShowString(8*8,2,oled_buffer,8);
        sprintf((char *)oled_buffer, "%-d", count_speedR);
        OLED_ShowString(8*8,4,oled_buffer,8);
    }
}

void TIMER_delay_INST_IRQHandler(void)
{
    Delay_ms++;
    if(Delay_ms==20){
        iu = false;

        //程序段

        Delay_ms = 0;
    }
    DL_Timer_clearInterruptStatus(TIMA0, DL_TIMER_INTERRUPT_ZERO_EVENT);//手动清除--
}
